package com.ruoyi.program.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.program.mapper.WxLearningMaterialMapper;
import com.ruoyi.program.domain.WxLearningMaterial;
import com.ruoyi.program.service.IWxLearningMaterialService;

/**
 * 资料上传Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-04
 */
@Service
public class WxLearningMaterialServiceImpl implements IWxLearningMaterialService 
{
    @Autowired
    private WxLearningMaterialMapper wxLearningMaterialMapper;

    /**
     * 查询资料上传
     * 
     * @param materialId 资料上传主键
     * @return 资料上传
     */
    @Override
    public WxLearningMaterial selectWxLearningMaterialByMaterialId(Long materialId)
    {
        return wxLearningMaterialMapper.selectWxLearningMaterialByMaterialId(materialId);
    }

    /**
     * 查询资料上传列表
     * 
     * @param wxLearningMaterial 资料上传
     * @return 资料上传
     */
    @Override
    public List<WxLearningMaterial> selectWxLearningMaterialList(WxLearningMaterial wxLearningMaterial)
    {
        return wxLearningMaterialMapper.selectWxLearningMaterialList(wxLearningMaterial);
    }

    /**
     * 新增资料上传
     * 
     * @param wxLearningMaterial 资料上传
     * @return 结果
     */
    @Override
    public int insertWxLearningMaterial(WxLearningMaterial wxLearningMaterial)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String username = loginUser.getUsername();

        // 为公共字段赋值
        wxLearningMaterial.setUserId(loginUser.getUserId());
        wxLearningMaterial.setCreateBy(username);  // 创建人
        wxLearningMaterial.setUpdateBy(username);  // 更新人（）
        wxLearningMaterial.setUpdateTime(new Date());  // 更新时间
        wxLearningMaterial.setCreateTime(DateUtils.getNowDate());
        return wxLearningMaterialMapper.insertWxLearningMaterial(wxLearningMaterial);
    }

    /**
     * 修改资料上传
     * 
     * @param wxLearningMaterial 资料上传
     * @return 结果
     */
    @Override
    public int updateWxLearningMaterial(WxLearningMaterial wxLearningMaterial)
    {
        wxLearningMaterial.setUpdateTime(DateUtils.getNowDate());
        return wxLearningMaterialMapper.updateWxLearningMaterial(wxLearningMaterial);
    }

    /**
     * 批量删除资料上传
     * 
     * @param materialIds 需要删除的资料上传主键
     * @return 结果
     */
    @Override
    public int deleteWxLearningMaterialByMaterialIds(Long[] materialIds)
    {
        return wxLearningMaterialMapper.deleteWxLearningMaterialByMaterialIds(materialIds);
    }

    /**
     * 删除资料上传信息
     * 
     * @param materialId 资料上传主键
     * @return 结果
     */
    @Override
    public int deleteWxLearningMaterialByMaterialId(Long materialId)
    {
        return wxLearningMaterialMapper.deleteWxLearningMaterialByMaterialId(materialId);
    }
}
